require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsCostGiftLinkHandler ={};
local this = RedDotsCostGiftLinkHandler;

function RedDotsCostGiftLinkHandler.init()
    CloseEvent(Config.EventType.Fresh_CostRedDot,this.update);
    ListenEvent(Config.EventType.Fresh_CostRedDot,this.update);

    return this;
end

-- 获取红点状态
function RedDotsCostGiftLinkHandler.getFlag(...)
    local state = logicMgr.CostManager.getFastConsumption();
    local openState = logicMgr.CostManager.getActiveOpenStatus(logicMgr.CostManager._FASTCONSUMPTION);
    local partnerId = ...;
    if tonumber(state) == 0 and openState ~= nil and openState then
        if partnerId == nil then
            return Config.RedDotsFlagState.Needful;
        else
            local savePartnerId = logicMgr.HeroManager.firstHeroPartnerId;
            if savePartnerId ~= nil and tostring(savePartnerId) == tostring(partnerId) then
                return Config.RedDotsFlagState.Needful;
            end
        end
    end
    return Config.RedDotsFlagState.None;
end

function RedDotsCostGiftLinkHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.CostGiftLink);
end